package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.BookDetailsDTO;
import bizlogic.Manager;

/**
 * Servlet implementation class CancelController
 */
@WebServlet("/CancelController")
public class CancelController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CancelController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doCancel(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doCancel(request, response);
	}
	private void doCancel(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String bookingID = request.getParameter("BookingID");
		Integer ID=Integer.valueOf(bookingID);
		Manager mg = new Manager();
		BookDetailsDTO bt = mg.FindByBookingID(ID);
		System.out.println(bt.toString());
		mg.cancel(bt);
		RequestDispatcher rd = request.getRequestDispatcher("/BookingHistoryController");
		rd.forward(request, response);
	}
	
}
